import { http } from "@/utils/http";
import { baseUrlApi } from "./utils";

export type gridProvinceResult = {
  code: number;
  message: string;
  data: {
    list: {
      provinceId: number;
      provinceName: string;
      provinceAbbr: string;
      so2Count: number;
      coCount: number;
      pmCount: number;
      aqiCount: number;
    };
  };
};

export type gridCityResult = {
  code: number;
  message: string;
  data: {
    list: {
      provinceId: number;
      provinceName: string;
      cityId: number;
      cityName: string;
    };
  };
};

/**根据城市id获取城市信息 */
export const getGridCityById = (cityId: number) => {
  return http.request<gridCityResult>(
    "get",
    baseUrlApi("/result/gridCity/getGridCityById"),
    {
      params: { cityId: cityId }
    }
  );
};

/**根据省份id获取城市信息 */
export const getGridCityByProvinceId = (provinceId: number) => {
  return http.request<gridCityResult>(
    "get",
    baseUrlApi(
      "/result/gridCity/getGridCityByProvinceId?provinceId=" + provinceId
    )
  );
};

/**根据省份ID获取省份信息 */
export const getGridProvinceById = (provinceId: number) => {
  return http.request<gridProvinceResult>(
    "get",
    baseUrlApi(
      "/result/gridProvince/getGridProvinceById?provinceId=" + provinceId
    )
  );
};

/**获取数据库中的所有省份信息 */
export const listProvinces = () => {
  return http.request<gridProvinceResult>(
    "post",
    baseUrlApi("/result/gridProvince/getAllGridProvinces")
  );
};
